package com.ruoyi.web.controller.test;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ContractPayment;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ServiceClassTransfer;
import com.ruoyi.system.service.IServiceClassTransferService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 业务类划转-CRUDController
 *
 * @author ruoyi
 * @date 2022-08-02
 */
@RestController
@RequestMapping("/system/transfer")
public class ServiceClassTransferController extends BaseController
{
    @Autowired
    private IServiceClassTransferService serviceClassTransferService;

    /**
     * 查询业务类划转-CRUD列表
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceClassTransfer serviceClassTransfer)
    {
        startPage();
        List<ServiceClassTransfer> list = serviceClassTransferService.selectServiceClassTransferList(serviceClassTransfer);
        return getDataTable(list);
    }

    /**
     * 导出业务类划转-CRUD列表
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:export')")
    @Log(title = "业务类划转-CRUD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceClassTransfer serviceClassTransfer)
    {
        List<ServiceClassTransfer> list = serviceClassTransferService.selectServiceClassTransferList(serviceClassTransfer);
        ExcelUtil<ServiceClassTransfer> util = new ExcelUtil<ServiceClassTransfer>(ServiceClassTransfer.class);
        util.exportExcel(response, list, "业务类划转-CRUD数据");
    }

    /**
     * 获取业务类划转-CRUD详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:query')")
    @GetMapping(value = "/{tranId}")
    public AjaxResult getInfo(@PathVariable("tranId") Long tranId)
    {
        return AjaxResult.success(serviceClassTransferService.selectServiceClassTransferByTranId(tranId));
    }

    /**
     * 新增业务类划转-CRUD
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:add')")
    @Log(title = "业务类划转-CRUD", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceClassTransfer serviceClassTransfer)
    {
        serviceClassTransfer.setUserId(getUserId());
        serviceClassTransfer.setDeptId(getDeptId());
        return toAjax(serviceClassTransferService.insertServiceClassTransfer(serviceClassTransfer));
    }

    /**
     * 修改业务类划转-CRUD
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:edit')")
    @Log(title = "业务类划转-CRUD", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceClassTransfer serviceClassTransfer)
    {
        return toAjax(serviceClassTransferService.updateServiceClassTransfer(serviceClassTransfer));
    }

    /**
     * 删除业务类划转-CRUD
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:remove')")
    @Log(title = "业务类划转-CRUD", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tranIds}")
    public AjaxResult remove(@PathVariable Long[] tranIds)
    {
        return toAjax(serviceClassTransferService.deleteServiceClassTransferByTranIds(tranIds));
    }
    /**
     * 导入数据管理列表
     */
    @Log(title = "数据管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ServiceClassTransfer> util = new ExcelUtil<ServiceClassTransfer>(ServiceClassTransfer.class);
        List<ServiceClassTransfer> serviceClassTransferList = util.importExcel(file.getInputStream());
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = getUsername();
        String message = serviceClassTransferService.importTransfer(serviceClassTransferList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<ServiceClassTransfer> util = new ExcelUtil<ServiceClassTransfer>(ServiceClassTransfer.class);
         util.importTemplateExcel(response,"案卷数据");
    }

}
